
$(function(){

	
	

	$(document).on('click','.audios',function(e){

		//$('<div></div>').appendTo($('body'))

		//console.log(e.target.nextSibling)

		var player = e.target.nextSibling; /*jquery对象转换成js对象*/
        

        if (player.paused){ /*如果已经暂停*/
            player.play(); /*播放*/
            $(e.target).attr('src','img/暂停.png')
        }else {
            player.pause();/*暂停*/
            $(e.target).attr('src','img/播放.png')
        }

        player.addEventListener('ended', function () {
        	$(e.target).attr('src','img/播放.png')
   		 }, false);

	})

	$('#copy').click(function(e){  //复制文本框内容

		$('#selectTleeInfo').select()

		document.execCommand("copy");

		layer=layui.layer

		layer.msg('复制成功',{icon: 6,time:1000})

	})


	$('#tellIput').click(function(e) {  //获取json数据遍历出 callId
		

		showloadHtml()

		$.post('json/tell.json',{},function(data,status){

			//console.log(JSON.parse(data))

			var dataArr=JSON.parse(data)

			var text=$('#txt').val()


			for(var i=0;i<dataArr.length;i++){

				//console.log(dataArr[i].callId)

				if(dataArr[i].phone==text){

					if(dataArr[i].fReason==0){

						pt(dataArr[i].callId)

					}

				}

			}	

		})

	})



	function pt(callId){  //获取通话详情 核心架构代码

			jsonData={"callId":callId}

			json=JSON.stringify(jsonData)

			

				$.post(

					'api.php',

					{data:json},

					function(data,status){
						
						setV(data.body)

						removeloadHtml()
						

					}
				)

	}



	function setV(data){  //通话记录显示


		//console.log(data)

		$('#name_Ai').html(data.name+'<br> 通话时长：'+data.calltime+'<br> 电话：'+data.phone )

		$('#time_Ai').html(data.starttime+'<br> 状态：'+data.myend)

		
		var duhuaList=data.list

		console.log(data)


		var audio_Ai=data.file_all

		var guanduan_Ai=data.myend


		$('#chat_Ai').html('')

		var AI_chat_html=''

		for(var i=0;i<duhuaList.length;i++){

			var ai=duhuaList[i].answer

			var user=duhuaList[i].content

			var data=duhuaList[i].addtime

			if(ai!==null){

				var duihua_AI= '<div class="dialog1"><div class="avatar1"><img src="img/a.jpg" /></div><div class="word1">'+ai+'</div></div>'

			}else{

				var duihua_AI= ''
			}

			if(user!==null){

				var duihua_user= '<div class="dialog2"><div class="avatar2"><div class="word2">'+user+'</div><img src="img/B.jpg" /></div></div>'

			}else{

				var duihua_user= ''

			}

			AI_chat_html+=(duihua_AI+duihua_user)


		}

		$('#chat_Ai').html(AI_chat_html)

		$('#audio').attr('src',audio_Ai)


		$('#play_Ai').attr('src','img/播放.png') 

		$("#audio")[0].pause()




	}

	$('#play_Ai').click(function(e){


		var player = $("#audio")[0]; /*jquery对象转换成js对象*/
        

        if (player.paused){ /*如果已经暂停*/
        	//player.fastSeek(10)
            player.play(); /*播放*/
            $('#play_Ai').attr('src','img/暂停.png')
        }else {
            player.pause();/*暂停*/
            $('#play_Ai').attr('src','img/播放.png')
        }

        player.addEventListener('ended', function (e) {
        	$('#play_Ai').attr('src','img/播放.png')
   		 }, false);


	})


	function showloadHtml(){

	 var $loathtml=$('<div id="load" class="loaded" style="position: absolute;left:50%;rigth:50%;top:50%"><div class="loaders"><div class="loader"><div class="loader-inner ball-pulse"><div></div><div></div><div></div></div></div></div></div>')

	 $('body').append($loathtml)

	}

	function removeloadHtml(){

		$('#load').remove()

	}
	
})
	